/*
 * Copyright (c) 2009 Roman Savelyev
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "ReadyForE32Image.h"
#include "AppHookModel.h"
#include "HostLink.h"
#include "Log.h"

static const TUint32 KResponseToHost = 0x900df00d;

CReadyForE32Image* CReadyForE32Image::NewL(CAppHookModel& aModel)
    {
    LOG(_L("-->CReadyForE32Image::NewL"));
    CReadyForE32Image* self = new(ELeave) CReadyForE32Image(aModel);
    self->Construct();
    LOG(_L("<--CReadyForE32Image::NewL"));
    return self;
    }

CReadyForE32Image::CReadyForE32Image(CAppHookModel& aModel) : CActive(CActive::EPriorityStandard),
    iModel(aModel),
    iResponseBuffer(KResponseToHost)
    {
    CActiveScheduler::Add(this);
    }

void CReadyForE32Image::Construct()
    {
    LOG(_L("-->CReadyForE32Image::Construct"));
    iStatus = KRequestPending;
    iModel.HostLink().WriteHost(iResponseBuffer, iStatus);
    SetActive();
    LOG(_L("<--CReadyForE32Image::Construct"));
    }

CReadyForE32Image::~CReadyForE32Image()
    {
    LOG(_L("-->CReadyForE32Image::~CReadyForE32Image"));
    Cancel();
    LOG(_L("<--CReadyForE32Image::~CReadyForE32Image"));
    }

void CReadyForE32Image::RunL()
    {
    TInt error = iStatus.Int();
    LOG2(_L("-->CReadyForE32Image::RunL(%d)"), error);
    if (KErrCancel != error)
        {
        iModel.ReadyForE32ImageComplete(error);
        }
    LOG(_L("<--CReadyForE32Image::RunL"));
    }

void CReadyForE32Image::DoCancel()
    {
    LOG(_L("-->CReadyForE32Image::DoCancel"));
    iModel.HostLink().CancelWriteHost();
    LOG(_L("<--CReadyForE32Image::DoCancel"));
    }
